#!/usr/bin/env python
# encoding: utf-8
# @author: Lin Han
# @contact: voldemort22@126.com
# @file: background_update.py
# @time: 2021/5/18 13:29
# @desc:
import time
import traceback
# from datetime import datetime

from crud import *

while True:
    # update_time = datetime.strptime(str(datetime.now().date())+'8:30', '%Y-%m-%d%H:%M')
    # if update_time.hour == datetime.now().hour:
    redis_connection = redis.StrictRedis(host=REDIS_IP, port=REDIS_PORT, db=0)
    redis_connection.set("stop-writes-on-bgsave-error", "no")

    try:
        extract_scene_to_redis()
    except:
        traceback.print_exc()

    try:
        udpate_history_clamp_data_board()
    except:
        traceback.print_exc()

    try:
        extract_history_clamp_from_mongo_to_redis()
    except:
        traceback.print_exc()

    try:
        update("history_part", collection_name=HISTORY_PART_COLLECTION)
    except:
        traceback.print_exc()

    try:
        extract_standard_clamp_from_mongo_to_redis()
    except:
        traceback.print_exc()

    try:
        update("standard_part", collection_name=STANDARD_PART_COLLECTION)
    except:
        traceback.print_exc()

    try:
        update("parameter_model", collection_name=PARAMETER_MODEL_COLLECTION)
    except:
        traceback.print_exc()

    time.sleep(3600)

